package app.bigdata;

import java.util.ArrayList;


public class Utils{
	
	public Utils(){}
	
	/*
	public static void getAVG(ArrayList<StarData> arrayList){
		int n = arrayList.size();
		double[] x = new double[n];
		double[] y = new double[n];
		double[] z = new double[n];
		double sumX = 0;
		double sumY = 0;
		double sumZ = 0;
		for(int i = 0 ; i < n ; i++){
			x[i] = Math.cos(arrayList.get(i).getLatitude())*Math.cos(arrayList.get(i).getLongitude());
			y[i] = Math.cos(arrayList.get(i).getLatitude())*Math.sin(arrayList.get(i).getLongitude());
			z[i] = Math.sin(arrayList.get(i).getLatitude());
			sumX = sumX + x[i];
			sumY = sumY + y[i];
			sumZ = sumZ + z[i];
		}
		double avgX = sumX/n;
		double avgY = sumY/n;
		double avgZ = sumZ/n;
		double r = Math.sqrt(avgX*avgX + avgY*avgY + avgZ*avgZ);
		double avgLat = Math.asin(avgZ/r);
		double avgLong = Math.atan(avgY/avgX);
	}
	*/
	
	/*
	// use Euclidean geometry
	public static int distance(float long1, float long2, float lat1 , float lat2) {
        int dist = 0;
        dist = (int)Math.sqrt( (double)((long1-long2)*(long1-long2)
              +(lat1-lat2)*(lat1-lat2)) );
        return dist;
	}
	*/
	
	/*
	// use Haversine formula
	public static int fineDistance(float long1, float long2, float lat1 , float lat2){
		float[] result = new float[3];
		Location location = new Location("start");
		location.distanceBetween(lat1,long1,lat2,long2,result);
		return (int)(result[0]/1000);	// make km
	}
	*/
	
	public static int fineDistance(double lon1, double lon2, double lat1, double lat2) {
		double theta = lon1 - lon2;
		double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + 
			Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
		dist = Math.acos(dist);
		dist = rad2deg(dist);
		dist = dist * 60 * 1.1515;
		return (int)(dist);
	}

	/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
	/*::  This function converts decimal degrees to radians             :*/
	/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
	private static double deg2rad(double deg) {
		return (deg * Math.PI / 180.0);
	}

	/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
	/*::  This function converts radians to decimal degrees             :*/
	/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
	private static double rad2deg(double rad) {
		return (rad * 180.0 / Math.PI);
	}
	
}